package com.meiyou.service.impl;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.meiyou.mapper.MeiyouSettingMapper;
import com.meiyou.mapper.custom.MeiyouChongzhiMapperCustom;
import com.meiyou.mapper.custom.MeiyouCyjlsMapperCustom;
import com.meiyou.mapper.custom.MeiyouGuideMapperCustom;
import com.meiyou.mapper.custom.MeiyouLyaskMapperCustom;
import com.meiyou.mapper.custom.MeiyouSettingMapperCustom;
import com.meiyou.mapper.custom.MeiyouShareMapperCustom;
import com.meiyou.mapper.custom.MeiyouShipinlsMapperCustom;
import com.meiyou.mapper.custom.MeiyouTixianMapperCustom;
import com.meiyou.mapper.custom.MeiyouTnaskMapperCustom;
import com.meiyou.mapper.custom.MeiyouTourMapperCustom;
import com.meiyou.mapper.custom.MeiyouTuinaMapperCustom;
import com.meiyou.mapper.custom.MeiyouUserMapperCustom;
import com.meiyou.mapper.custom.MeiyouYhaskMapperCustom;
import com.meiyou.mapper.custom.MeiyouYueHuiMapperCustom;
import com.meiyou.mapper.custom.MeiyougbaskMapperCustom;
import com.meiyou.pojo.MeiyouSetting;
import com.meiyou.pojo.MeiyouUser;
import com.meiyou.pojo.ShuJu;
import com.meiyou.service.ShuJuService;

@Service("ShuJuService")
public class ShujuServiceImpl implements ShuJuService{

	@Autowired
	MeiyouSettingMapper meiyouSettingMapper;
	@Autowired
	MeiyouSettingMapperCustom meiyouSettingMapperCustom;
	@Autowired
	MeiyouUserMapperCustom meiyouUserMapperCustom;
	@Autowired
	MeiyouShareMapperCustom meiyouShareMapperCustom;
	@Autowired
	MeiyouGuideMapperCustom meiyouGuideMapperCustom;
	@Autowired
	MeiyouTourMapperCustom meiyouTourMapperCustom;
	@Autowired
	MeiyouTuinaMapperCustom meiyouTuinaMapperCustom;
	@Autowired
	MeiyouYueHuiMapperCustom meiyouYueHuiMapperCustom;
	@Autowired
	MeiyouCyjlsMapperCustom meiyouCyjlsMapperCustom;
	@Autowired
	MeiyouChongzhiMapperCustom meiyouChongzhiMapperCustom;
	@Autowired
	MeiyouTixianMapperCustom meiyouTixianMapperCustom;
	@Autowired
	MeiyouShipinlsMapperCustom meiyouShipinlsMapperCustom;
	@Autowired
	MeiyouLyaskMapperCustom meiyouLyaskMapperCustom;
	@Autowired
	MeiyouTnaskMapperCustom meiyouTnaskMapperCustom;
	@Autowired
	MeiyouYhaskMapperCustom meiyouYhaskMapperCustom;
	@Autowired
	MeiyougbaskMapperCustom meiyougbaskMapperCustom;
	
	
	public int updateFXgetMeijin(String quantity) {
		// TODO Auto-generated method stub
		MeiyouSetting  meiyouSetting = new MeiyouSetting();
		meiyouSetting.setjId(8);
		meiyouSetting.setjName("fenxiangjin");
		meiyouSetting.setjValue(quantity); 
		return meiyouSettingMapper.updateByPrimaryKey(meiyouSetting); 
	}

	
	public int updateCYJgetMeijin(String quantity) {
		// TODO Auto-generated method stub
		MeiyouSetting  meiyouSetting = new MeiyouSetting();
		meiyouSetting.setjId(4);
		meiyouSetting.setjName("chenyijin");
		meiyouSetting.setjValue(quantity); 
		return meiyouSettingMapper.updateByPrimaryKey(meiyouSetting); 
	}

	
	public int updateFBJgetMeijin(String quantity) {
		// TODO Auto-generated method stub
		MeiyouSetting  meiyouSetting = new MeiyouSetting();
		meiyouSetting.setjId(6);
		meiyouSetting.setjName("fabujin");
		meiyouSetting.setjValue(quantity); 
		return meiyouSettingMapper.updateByPrimaryKey(meiyouSetting);
	}

	
	public int updateTXgetMeijin(String quantity) {
		// TODO Auto-generated method stub
		MeiyouSetting  meiyouSetting = new MeiyouSetting();
		meiyouSetting.setjId(7);
		meiyouSetting.setjName("tixian");
		meiyouSetting.setjValue(quantity); 
		return meiyouSettingMapper.updateByPrimaryKey(meiyouSetting); 
	}

	
	public int updateZDgetMeijin(String quantity) {
		// TODO Auto-generated method stub
		MeiyouSetting  meiyouSetting = new MeiyouSetting();
		meiyouSetting.setjId(1);
		meiyouSetting.setjName("zhiding");
		meiyouSetting.setjValue(quantity); 
		return meiyouSettingMapper.updateByPrimaryKey(meiyouSetting); 
	}

	
	public List<MeiyouSetting> getalldata() {
		// TODO Auto-generated method stub
		return meiyouSettingMapper.selectByExample(null); 
	}

	
	public int updateTHgetMeijin(String quantity) {
		// TODO Auto-generated method stub
		MeiyouSetting  meiyouSetting = new MeiyouSetting();
		meiyouSetting.setjId(9);
		meiyouSetting.setjName("tonghuafei");
		meiyouSetting.setjValue(quantity); 
		return meiyouSettingMapper.updateByPrimaryKey(meiyouSetting); 
	}

	
	@Transactional(propagation=Propagation.SUPPORTS)
	public ShuJu getAllShujuByDate(String date) {
		// TODO Auto-generated method stub
		ShuJu shuju = new ShuJu();
		//注册数
		List<MeiyouUser> list = meiyouUserMapperCustom.selectUserbyDate(date);
		shuju.setVolumeNumber(list.size()+""); 
		//分享金币数
		String fenxiangjin = meiyouShareMapperCustom.selectFXJByDate(date);
		if(fenxiangjin==null) {
			fenxiangjin = "0.0";
		}
		shuju.setFenxiangJin(fenxiangjin); 
		//总发需求数
		int guide = meiyouGuideMapperCustom.selectGuidebyDate(date);
		int tour = meiyouTourMapperCustom.selectTourByDate(date);
		int yuehui = meiyouYueHuiMapperCustom.selectYuehuiByDate(date);
		int tuina = meiyouTuinaMapperCustom.selectTuinaBydate(date);
		String xuqiushu = (guide+tour+yuehui+tuina)+"";
		shuju.setNeedData(xuqiushu); 
		//悬赏金币
		String guideMj = meiyouGuideMapperCustom.selectMejinbyDate(date);
		if(guideMj==null) {
			guideMj="0";
		}
		String tourMj = meiyouTourMapperCustom.selectMeijinByDate(date);
		if(tourMj==null) {
			tourMj="0";
		}
		String yuehuiMj = meiyouYueHuiMapperCustom.selectMeijinByDate(date);
		if(yuehuiMj==null) {
			yuehuiMj="0";
		}
		String tuinaMj = meiyouTuinaMapperCustom.selectMeijinBydate(date);
		if(tuinaMj==null) {
			tuinaMj="0";
		}
		String sumMj = (Double.parseDouble(guideMj)+Double.parseDouble(tourMj)+Double.parseDouble(yuehuiMj)+Double.parseDouble(tuinaMj))+"";
		shuju.setPostReward(sumMj); 
		//诚意金收益
		String chenyijin = meiyouCyjlsMapperCustom.selectCYJbyDate(date);
		if(chenyijin==null) {
			chenyijin="0";
		}
		shuju.setChenyijin(chenyijin); 
		//平台费收益  先查询发布金
		String fabujin = meiyouSettingMapperCustom.selectValueBykey("fabujin");
		String pingtaifei = (Double.parseDouble(fabujin))*(Double.parseDouble(xuqiushu))+"";
		shuju.setPingtaifei(pingtaifei); 
		//充值金币总数
		String chongzhi = meiyouChongzhiMapperCustom.selectCZMeijinByDate(date);
		if(chongzhi==null) {
			chongzhi = "0";
		}
		shuju.setChongzhi(chongzhi);
		//提现金额   先查出提现率
		String tixianlv = meiyouSettingMapperCustom.selectValueBykey("tixian");
		String tixianjinbi = meiyouTixianMapperCustom.selectTXJE(date);
		System.out.println(tixianlv+"||"+tixianjinbi);
		String tixian = "0";
		if(tixianjinbi!=null) {
			tixian = Double.parseDouble(tixianjinbi)*Double.parseDouble(tixianlv)+"";
		}
		shuju.setTixian(tixian);
		//视频聊天收益
		String shipin = meiyouShipinlsMapperCustom.selectMeijinByDate(date);
		if(shipin==null) {
			shipin = "0";
		}
		shuju.setShipingfei(shipin);
		//报名人数
		String lyrs = meiyouLyaskMapperCustom.selectRenshuByDate(date);
		System.out.println(lyrs);
		String tnrs = meiyouTnaskMapperCustom.selectRenshuByDate(date);
		System.out.println(lyrs);
		String yhrs = meiyouYhaskMapperCustom.selectRenshuByDate(date);
		System.out.println(lyrs);
		String gbrs = meiyougbaskMapperCustom.selectRenshuByDate(date);
		System.out.println(lyrs);
		String numrenshu = Integer.parseInt(lyrs)+
				Integer.parseInt(tnrs)+
				Integer.parseInt(yhrs)+
				Integer.parseInt(gbrs)+"";
		
		shuju.setBaominshu(numrenshu); 
		System.out.println(shuju);
 		return shuju;
	}
}
